//
//  EJSMineTableViewCell.m
//  24Gou
//
//  Created by lifayu on 2018/11/2.
//  Copyright © 2018 lifayu. All rights reserved.
//

#import "EJSMineTableViewCell.h"
#import "FlyCollectionViewAlignFlowLayout.h"
#import "EJSMineCollectionViewCell.h"

@implementation EJSMineTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    FlyCollectionViewAlignFlowLayout *layout = [[FlyCollectionViewAlignFlowLayout alloc] initLayoutWithCollectionViewAlignType:FlyCollectionViewAlignLeft];
    layout.sectionInset = UIEdgeInsetsMake(0, 9, 0, 9);
    [self.collectionView setCollectionViewLayout:layout];
    [self.collectionView registerNib:[UINib nibWithNibName:@"EJSMineCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"EJSMineCollectionViewCell"];
}

- (void)setToolLisModel:(EJSMineToolListModel *)toolLisModel{
    _toolLisModel = toolLisModel;
    [self.collectionView reloadData];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _toolLisModel.items.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    EJSMineCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EJSMineCollectionViewCell" forIndexPath:indexPath];
    cell.toolModel = _toolLisModel.items[indexPath.item];
    return cell;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((ScreenWidth - 60)/4.0, collectionView.height);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if(_delegate && [_delegate respondsToSelector:@selector(tableViewCell:didSelectCollectionViewIndexPath:)]){
        [_delegate tableViewCell:self didSelectCollectionViewIndexPath:indexPath];
    }
}

@end
